// components/nearby_mch/nearby_mch.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    api_host: {
      type: String
    },
    show_num: {
      type: Number,
      value: 5
    },
    show_goods_num: {
      type: Number,
      valye: 6
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    loading: false,
    list: []
  },

  /**
   * 组件的方法列表
   */
  methods: {
    goToShopList: function () {
      wx.navigateTo({
        url: '/pages/shop-list/shop-list',
      })
    },
    getData: function (longitude, latitude) {
      var self = this;
      this.setData({
        loading: true
      })
      getApp().request({
        url: getApp().api.mch.mch_list,
        method: "GET",
        data: {
          longitude: longitude,
          latitude: latitude,
          limit: this.data.show_num,
          goods_limit: this.data.show_goods_num
        },
        success: function (t) {
          if (t.code == 0) {
            self.setData({
              list: t.data.list
            })
          }
        },
        complete: function () {
          self.setData({
            loading: false
          })
        }
      });
    },
    goToUrl: function (e) {
      var id = e.currentTarget.dataset.id
      wx.navigateTo({
        url: '/mch/shop/shop?mch_id=' + id,
      })
    },
	goToGoods: function (e) {
      var id = e.currentTarget.dataset.id
      wx.navigateTo({
        url: '/pages/goods/goods?id=' + id,
      })
    }
  },

  lifetimes: {
    attached: function () {
      var self = this;
      wx.getLocation({
        success: function (t) {
          self.getData(t.longitude, t.latitude)
        },
        complete: function () {
        }
      });
    }
  }
})
